<template>
  <div class="login-container">
    <!-- header -->
    <div class="header-wrapper">
      <div class="header">
        <div style="width: 325px;">
          <el-row>
            <el-col>
              <!--<img src="@/assets/images/slogo.png" width="200px" height="55">-->
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
    <!-- 表单 -->
    <div class="login-form__wrap">
      <div class="fl login-form__left">
        <img src="@/assets/images/loginbs.png">
      </div>
      <div class="fr login-form__right">
        <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
          <div class="title-container">
            <h3 class="title">房云后台管理系统</h3>
          </div>
          <div class="mian-container">
            <el-form-item prop="username">
              <span class="svg-container">
                <img-icon size="1" imgname="user" />
              </span>
              <el-input
                v-model="loginForm.userName"
                placeholder="请输入用户名"
                name="username"
                type="text"
                auto-complete="on"
              />
            </el-form-item>
            <el-form-item prop="password">
              <span class="svg-container">
                <img-icon size="1" imgname="key" />
              </span>
              <el-input
                :type="passwordType"
                v-model="loginForm.password"
                placeholder="请输入密码"
                name="password"
                auto-complete="on"
              />
            </el-form-item>
            <div class="login-btn">
              <el-button :loading="loading" type="primary" @click.native.prevent="handleLogin">登录</el-button>
            </div>
          </div>
        </el-form>
      </div>
    </div>
    <div class="footer">
      <div class="container">
        <div class="foot-info">
          <p class="pt-12">©2015-2017深圳国裕网络科技有限公司 粤公网安备44030502000920号</p>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import ImgIcon from '@/components/ImgIcon'
export default {
  name: 'Login',
  components: { ImgIcon },
  data() {
    const validateUsername = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入用户名'))
      } else {
        callback()
      }
    }
    const validatePassword = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入密码'))
      } else if (value.length < 6) {
        callback(new Error('密码不能小于6位'))
      } else {
        callback()
      }
    }
    return {
      loginForm: {
          userName: '',
          password: ''
      },
      loginRules: {
          userName: [{ required: true, trigger: 'blur', validator: validateUsername }],
          password: [{ required: true, trigger: 'blur', validator: validatePassword }]
      },
      passwordType: 'password',
      loading: false,
      showDialog: false,
      redirect: undefined
    }
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect
      },
      immediate: true
    }
  },
  methods: {
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
    },
    handleLogin() {

      this.$refs.loginForm.validate(valid => {
        if (valid) {
          // if(this.loginForm.username !== 'admin' || this.loginForm.password !== '123456') {
          //     this.$message({
          //         type: 'error',
          //         message: `用户账号或密码错误!`
          //     })
          //     return
          // }
          this.loading = true
          this.$store.dispatch('LoginByUsername', this.loginForm).then(() => {
            this.loading = false
            this.$router.push({ path: this.redirect || '/project/index' })
          }).catch(() => {
            this.loading = false
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
  /* 修复input 背景不协调 和光标变色 */
  /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  $bg:#283443;
  $light_gray:#666;
  $cursor: #fff;
  @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
    .login-container .el-input input{
      color: $cursor;
      &::first-line {
        color: $light_gray;
      }
    }
  }
  /* reset element-ui css */
  .login-container {
    position: absolute;
    height: 100%;
    background: #E7F7FB;
    .el-input {
      display: inline-block;
      height: 47px;
      width: 75%;
      input {
        background: transparent;
        border: 0px;
        -webkit-appearance: none;
        border-radius: 0px;
        padding: 10px 5px 12px 15px;
        height: 47px;
        font-size: 16px;
        color:#999;
        &:-webkit-autofill {
          -webkit-box-shadow: 0 0 0px 1000px $bg inset !important;
          -webkit-text-fill-color: $cursor !important;
        }
      }
    }
  }
</style>

<style rel="stylesheet/scss" lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#666;
.header-wrapper{
  .header{
    padding:65px 50px;
    img {
      width: 100%
    }
  }
}
.login-container {
  width: 100%;
  .login-form__wrap{
    width: 720px;
    height: 450px;
    margin: 0 auto;
    background: #fff;
    border-radius: 5px;
    .login-form__left {
      width: 300px;
      height: 450px;
      img {
        width: 100%;
        height: 100%
      }
    }
  }
  .login-form {
    left: 0;
    right: 0;
    width:372px;
    max-width: 100%;
    margin: 0 auto;
    background: #fff;
    border-radius: 5px;
    .mian-container{
      padding:40px 40px 35px;
      >>>.el-form-item{
        border:none;
        border-bottom:1px solid #f0edf7;
        box-sizing: border-box;
        color: #454545;
        margin-bottom: 25px;
        >>>.el-form-item__content{
          border:1px solid red;
        }
      }
    }
  }
  .svg-container {
    padding: 6px 25px 0px 15px;
    color: #1e88e5;
    vertical-align: middle;
    display: inline-block;
  }
  .title-container {
    position: relative;
    /*background: url("../../assets/images/login.png") no-repeat top center;*/
    /*background-size: 100%;*/
    .title {
      font-size: 18px;
      font-weight: bold;
      color: #1e88e5;
      padding: 40px 0 0 40px;
      border-bottom: none;
      letter-spacing: 7px;
    }
  }
  .login-btn{
    width:293px;
    height:75px;
    padding:2px;
    margin-top:30px;
    background: url('../../assets/images/login-btn.png') no-repeat;
    >>>button{
      width:285px;
      font-size:20px;
      background: #1e88e5;
      height:45px;
      border: none;
      letter-spacing: 4px;
    }
  }
  .footer{
    background: none;
    width:100%;
    font-size:14px;
    color:#666666;
    text-align: center;
    .foot-info{
      padding-top:80px;
    }
  }
}
.placeholder {
  position: absolute;
  top: 0px;
  left: 10px !important;
  z-index: 10;
  color: #aaaaaa;
}
</style>
